package org.micro.test.controller;

import com.baomidou.mybatisplus.plugins.Page;
import org.micro.test.entity.ResultDto;
import org.micro.test.service.IUseCaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/useCase")
public class UseCaseController {
    @Autowired
    private IUseCaseService useCaseService;
    /**
     * BootStrap Table分页
     * @param pageNumber 页数
     * @param pageSize 每页显示数据的条数
     * @param searchText 搜索关键字
     */
    @GetMapping("/getAllUseCase")
    public Object getAllUseCase(Integer pageSize, Integer pageNumber, String searchText){
        //搜索框功能
        //当查询条件中包含中文时，get请求默认会使用ISO-8859-1编码请求参数，在服务端需要对其解码
        if (null != searchText) {
            try {
                searchText = new String(searchText.getBytes("ISO-8859-1"), "UTF-8");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        ResultDto resultDto = new ResultDto();
        Page page = new Page(pageNumber, pageSize);
        page = useCaseService.selectByPage(page);
        resultDto.setTotal(page.getTotal());
        resultDto.setRows(page.getRecords());
        return resultDto;
    }
}
